﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using org.owasp.validator.html;

namespace SocialFront
{
    public static class AntiSamy
    {
        private static string _filename = System.Web.HttpContext.Current.Server.MapPath(Config.sfSanitizationConfig);

        private static Policy GetPolicy()
        {
            return Policy.getInstance(_filename);
        }

        private static string GetSanitizedContent(string dirtyString)
        {
            org.owasp.validator.html.AntiSamy antiSamy = new org.owasp.validator.html.AntiSamy();

            return antiSamy.scan(dirtyString, GetPolicy()).getCleanHTML();
        }

        public static string Sanitize(this string dirtyString)
        {
            return GetSanitizedContent(dirtyString);
        }
    }
}